const { name } = require('./package')
const path = require('path')
const MonacoEditorPlugin = require('monaco-editor-webpack-plugin')

module.exports = {
  devServer: {
    port: '8081',
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  },
  outputDir: 'lib',
  chainWebpack: (config) => {
    config.module
      .rule('fonts')
      .use('url-loader')
      .loader('url-loader')
      .options({})
      .end()
    config.module
      .rule('images')
      .use('url-loader')
      .loader('url-loader')
      .options({})
      .end()
    config.plugin('monaco').use(new MonacoEditorPlugin())
  },
  configureWebpack: {
    output: {
      library: `${name}-[name]`,
      libraryTarget: 'umd', // 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_${name}`
    },
    resolve: {
      alias: {
        '@formily/core': path.resolve(
          process.cwd(),
          'node_modules',
          '@formily/core'
        )
      }
    }
  }
}
